import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/viewmodel/medecine/take_medicine/add_take_medicine_view_model.dart';

import '../../../res/gaps.dart';
import '../../../widgets/common_widget.dart';
class AddTakeMedicinePage extends BaseStatefulMvvmWidget{

  @override
  State<StatefulWidget> createState() => _AddTakeMedicineState();

}

class _AddTakeMedicineState extends BaseMvvmState<AddTakeMedicineViewModel,AddTakeMedicinePage>{
  @override
  Widget? buildLoadingContentView() {
    return Column(
      children: [
        SingleChildScrollView(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: Column(
            children: [
              ...[
                TitleValueWidget(
                    title: '长者姓名',
                    isRequired: true,
                    value: viewModel.elderInfo?.customerName ?? "",
                    arrow: Icon(Icons.keyboard_arrow_right_outlined))
                    .onTap(() {
                  viewModel.chooseElder();
                },
                    highlightColor: Colors.transparent,
                    splashColor: Colors.transparent),
                TitleValueWidget(
                    title: '床位号',
                    value: viewModel.elderInfo?.bedNo ?? "",
                    hint: '根据长者自动显示'),
                TitleValueWidget(
                    title: '性别',
                    value: viewModel.elderInfo?.sexName ?? "",
                    hint: '根据长者自动显示'),
                TitleValueWidget(
                    title: '药品名称',
                    isRequired: true,
                    value: viewModel.drugInfo?.commonName??"",
                    arrow: Icon(Icons.keyboard_arrow_right_outlined))
                    .onTap(() {
                  viewModel.chooseMedicine();
                },
                    highlightColor: Colors.transparent,
                    splashColor: Colors.transparent),
                TitleValueWidget(title: '药品规格', value: viewModel.drugInfo?.specifications??"", hint: '根据选择的药品自动显示'),
                TitleValueWidget(title: '包装单位', value: viewModel.drugInfo?.maxUnitName??"", hint: '根据选择的药品自动显示'),
                TitleValueWidget(title: '最小单位', value: viewModel.drugInfo?.minUnitName??"", hint: '根据选择的药品自动显示'),
                TitleContentWidget(
                    title: '用量',
                    isRequired: true,
                    child: NoBorderInput(
                        hintText: '仅输入正整数',
                        onChanged: (str) {
                          setState(() {
                            viewModel.useNum = str;
                          });
                        },
                        maxLines: 1,
                        keyboardType: CommonInputType.number)),
                TitleValueWidget(
                    title: '服药时间',
                    isRequired: true,
                    value: viewModel.planTime,
                    arrow: Icon(Icons.keyboard_arrow_right_outlined))
                    .onTap(() {
                  viewModel.choosePlanTime();
                },
                    highlightColor: Colors.transparent,
                    splashColor: Colors.transparent),
                TitleValueWidget(
                    title: '服药时间',
                    isRequired: true,
                    value: viewModel.useTime?.name ?? "",
                    arrow: Icon(Icons.keyboard_arrow_right_outlined))
                    .onTap(() {
                  viewModel.chooseUseTime();
                },
                    highlightColor: Colors.transparent,
                    splashColor: Colors.transparent),
              ].insertWidget(Gaps.dividerLine)
            ],
          ),
        ).setWeight(1),
        SizedBox(height: 10,),
        TextButton(
          onPressed: () {
            viewModel.submitAdd();
          },
          child: CommonText('确认', textColor: Colors.white),
          style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Colors.blue),
              shape: WidgetStateProperty.all(StadiumBorder()),
              minimumSize: WidgetStateProperty.all(Size(MediaQuery.of(context).size.width-32, 45))),
        ),
        SizedBox(height: 20,)
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('新增服药'),
      ),
      body: loadingContentWidget,
    );
  }


  @override
  AddTakeMedicineViewModel createViewModel() {
    return AddTakeMedicineViewModel(context);
  }

  @override
  void onRetryClick() {
    // TODO: implement onRetryClick
  }

}